package com.stepshop.core.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class InitServlet
 */
@WebServlet("/InitServlet")
public class InitServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InitServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		response.getWriter();
//		response.getWriter().append("Served at: ").append(request.getContextPath());
//		request.getRequestDispatcher("index.jsp").forward(request, response);
//		ServletOutputStream os= response.getOutputStream();
		response.setContentType("text/plain;chatset=utf-8");
		response.setHeader("Content-Disposition","attachment; filename=foobar.txt");
		PrintWriter writer = response.getWriter();
		byte[] by=new byte[]{0,1,1,1,1,0,1,1};
		String str=new String(by,"UTF-8");
		System.out.println(str);
		writer.write(str);
		writer.flush();
		writer.close();
//		os.write(by);
//		os.flush();
//		os.close();
//		response.sendRedirect("index.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
